<script lang="js" setup>
import {
  createWeb3Modal,
  defaultWagmiConfig,
  useWeb3ModalState
} from '@web3modal/wagmi/vue'
import { mainnet, arbitrum } from 'viem/chains'
import {
  signMessage,
  getAccount,
  sendTransaction,
  waitForTransaction,
  writeContract,
  readContract,
  prepareWriteContract, erc20ABI,
  fetchFeeData
} from '@wagmi/core'
import {parseEther, parseGwei} from 'viem'


// 1. Get projectId at https://cloud.walletconnect.com
const projectId = 'd5d55078e99cf6446afdf1914a2db368'

// 2. Create wagmiConfig
const metadata = {
  name: 'shipBoxs',
  description: 'ShipBoxs',
  url: 'https://shipboxs.com',
  icons: ['https://avatars.githubusercontent.com/u/37784886']
}

// 这里是选择evm区块链技术构建的网络，goerli是测试网
// const chains = [mainnet, arbitrum]
const chains = [mainnet]

const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })

// 3. Create modal
const modal = createWeb3Modal({ wagmiConfig, projectId, chains })

const useModalRes = useWeb3ModalState()

// 签名 目前还不知道这个签名的作用是什么，先全部测试下这些api就知道了
const toSignature = async () => {
  const signature = await signMessage({
    message: 'gm wagmi frens',
  })
  console.log('sign', signature)
}

// 获取当前连接的钱包的账户信息，我们可以在进来页面的时候，调取这个，然后可以查询到当前是否连接了钱包，以及连接的钱包的地址
const toGetAccount = async () => {
  const account = await getAccount()
  console.log('账户信息',account)
}

/**
 * 获取代币address和abi
 * @param name
 * @returns {{address: string, name: string, abi: [{outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}, {name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}], name: string, stateMutability: string, type: string}, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]} | {address: string, name: string, abi: [{outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}, {name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, null, null, null, null]} | {address: string, name: string, abi: [{outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: [{name: string, type: string}, {name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: *[], constant: boolean, payable: boolean, inputs: [{name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]} | {address: string, name: string, abi: [{outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: [{name: string, type: string}, {name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: [{name: string, type: string}, {name: string, type: string}, {name: string, type: string}], name: string, stateMutability: string, type: string}, {outputs: [{name: string, type: string}], constant: boolean, payable: boolean, inputs: *[], name: string, stateMutability: string, type: string}, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]}}
 */
const getToken = (name) => {
  const fined = [
    {
      address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
      name: 'USDT',
      abi: [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_upgradedAddress","type":"address"}],"name":"deprecate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"deprecated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_evilUser","type":"address"}],"name":"addBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"upgradedAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maximumFee","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_maker","type":"address"}],"name":"getBlackListStatus","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowed","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newBasisPoints","type":"uint256"},{"name":"newMaxFee","type":"uint256"}],"name":"setParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"issue","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"redeem","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"basisPointsRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBlackListed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_clearedUser","type":"address"}],"name":"removeBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MAX_UINT","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_blackListedUser","type":"address"}],"name":"destroyBlackFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_initialSupply","type":"uint256"},{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Issue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"amount","type":"uint256"}],"name":"Redeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newAddress","type":"address"}],"name":"Deprecate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"feeBasisPoints","type":"uint256"},{"indexed":false,"name":"maxFee","type":"uint256"}],"name":"Params","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_blackListedUser","type":"address"},{"indexed":false,"name":"_balance","type":"uint256"}],"name":"DestroyedBlackFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"AddedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_user","type":"address"}],"name":"RemovedBlackList","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"}]
    },
    {
      address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
      name: 'USDC',
      abi: [{"constant":false,"inputs":[{"name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newImplementation","type":"address"},{"name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"admin","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_implementation","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"previousAdmin","type":"address"},{"indexed":false,"name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"implementation","type":"address"}],"name":"Upgraded","type":"event"}]
    },
    {
      address: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
      name: 'BTC',
      abi: [{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_token","type":"address"}],"name":"reclaimToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"value","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"claimOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pendingOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"burner","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
    },
    {
      address: '0x0aBCFbfA8e3Fda8B7FBA18721Caf7d5cf55cF5f5',
      name: 'LTC',
      abi: [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"},{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"},{"name":"bindaddr","type":"string"}],"name":"Swapout","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"changeDCRMOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"txhash","type":"bytes32"},{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"Swapin","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"oldOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"},{"indexed":true,"name":"effectiveHeight","type":"uint256"}],"name":"LogChangeDCRMOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"txhash","type":"bytes32"},{"indexed":true,"name":"account","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"LogSwapin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"bindaddr","type":"string"}],"name":"LogSwapout","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]
    }
  ].find(row => row.name === name)
  // fined.abi = erc20ABI
  return fined
}

// 发起交易 本币交易
const toTransaction = async () => {
  console.log('发起交易-开始')
  const { hash } = await sendTransaction({
    to: '0xAFe47Abf1b2140014cEaE19140BBB9Ffb31047f7', // 接收者的钱吧地址 我测试的接收地址是metamask地址
    value: parseEther('0.00001'), // 发送的币种数量
  })
  console.log('交易hash', hash)
  const data = await waitForTransaction({
    hash
  })
  console.log('交易结果', data)
}

// 获取单位
const toDecimals = async (token) => {
  const res = await readContract({
    address: token.address,
    abi: token.abi,
    functionName: 'decimals',
    args: [],
  })
  console.log(typeof res, res + '', '精度单位')
  return Number(res + '')
}

// 获取gas费用
const toFetchFeeData = async () => {
  const feeData = await fetchFeeData({
    formatUnits: 'gwei',
  })
  console.log('gas:', feeData)
  console.log('gas,usdt', parseGwei('13'))
  return feeData
}

// 发起交易 代币交易
const toWriteContract = async () => {
  const token = getToken('USDT')
  const decimal = await toDecimals(token)
  const feeData = await toFetchFeeData()

  const config = await prepareWriteContract({
    address: token.address,
    abi: token.abi,
    functionName: "transfer",
    // 下面是表示1个整数单位的币 BigInt(10 ** decimal)
    args: ['0xAFe47Abf1b2140014cEaE19140BBB9Ffb31047f7', BigInt(0.01 * 10 ** decimal)],
    // maxFeePerGas: feeData.maxFeePerGas,
    // maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
    // gasPrice: 13000000000n,
    // gas: 14n,
    value: 0
  })

  const { hash } = await writeContract(config)

  // const res = await readContract({
  //   address: token.address,
  //   abi: token.abi,
  //   functionName: 'balanceOf',
  //   args: ['0x6D26818F473E4FED4C47FfD2b3607D4D638248E7'],
  // })
  console.log('调取合约返回值', hash)
  // 0x9bc6960766257C6742F6Fa09460B8D7041923989 老板钱包地址
  // 0x6D26818F473E4FED4C47FfD2b3607D4D638248E7 我的metamask地址
  // 0xAFe47Abf1b2140014cEaE19140BBB9Ffb31047f7 我的欧易地址

  // https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#writeContract#F2
  // transfer (0xa9059cbb)
  // https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#writeProxyContract#F17
}

// 3183455903047000
// 13742509053000000000

</script>

<template>
  <div style="width: 100%;height: 100vh;display: flex;align-items: center;justify-content: center;flex-flow: column nowrap">
    <w3m-button />
    <w3m-network-button />
    <button style="margin-top: 10px;" @click="toSignature()">签名</button>
    <div style="margin-top: 10px;">
      {{ JSON.stringify(useModalRes, null, 2) }}
    </div>
    <button @click="toGetAccount()" style="margin-top: 10px;">获取连接的钱包的账户信息</button>
    <button @click="toTransaction()" style="margin-top: 10px;">发起eth交易</button>
    <button @click="toFetchFeeData()" style="margin-top: 10px;">获取gas费用</button>
    <button @click="toWriteContract()" style="margin-top: 10px;">发起代币交易</button>
  </div>
</template>